import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:flutter_yn_goods/base/widget/base_list_more_get_builder.dart';
import 'package:flutter_yn_goods/config/app_color.dart';
import 'package:flutter_yn_goods/config/app_translations.dart';
import 'package:flutter_yn_goods/pages/agent_order_list/agent_order_list_logic.dart';
import 'package:flutter_yn_goods/pages/model/model_user_want.dart';
import 'package:flutter_yn_goods/utils/utils_other.dart';
import 'package:flutter_yn_goods/widgets/appbar/common_app_bar.dart';
import 'package:flutter_yn_goods/widgets/image/image_view.dart';
import 'package:flutter_yn_goods/widgets/widget_line.dart';
import 'package:get/get.dart';

class AgentOrderListPage extends StatelessWidget {
  final logic = Get.put(AgentOrderListLogic());

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: CommonAppBar(
        title: LocaleKeys.agent_order_list.tr,
      ),
      body: BaseListMoreGetBuilder<AgentOrderListLogic>(
        init: logic,
        builder: (logic) {
          return ListView.builder(
            itemCount: logic.list.length,
            padding: EdgeInsets.symmetric(horizontal: 16.w, vertical: 12.h),
            itemBuilder: (context, index) {
              return _buildOrderItem(logic.list[index]);
            },
          );
        },
      ),
    );
  }

  Widget _buildOrderItem(ModelUserWant order) {
    return Container(
      margin: EdgeInsets.only(bottom: 12.h),
      decoration: BoxDecoration(
        color: Colors.white,
        borderRadius: BorderRadius.circular(8.w),
        boxShadow: [
          BoxShadow(
            color: Colors.black.withOpacity(0.05),
            blurRadius: 6,
            offset: Offset(0, 2),
          ),
        ],
      ),
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          // 顾客信息部分
          Padding(
            padding: EdgeInsets.all(12.w),
            child: Row(
              children: [
                // 顾客头像
                ClipRRect(
                  borderRadius: BorderRadius.circular(20.w),
                  child:  ImageView(
                          imageUrl: order.phone,
                          width: 40.w,
                          height: 40.w,
                          fit: BoxFit.cover,
                        )


                ),
                SizedBox(width: 10.w),
                // 顾客信息
                Expanded(
                  child: Column(
                    crossAxisAlignment: CrossAxisAlignment.start,
                    children: [
                      Text(
                        order.nickname ?? LocaleKeys.no_data.tr,
                        style: TextStyle(
                          fontSize: 14.sp,
                          fontWeight: FontWeight.bold,
                          color: AppColor.color202020,
                        ),
                      ),
                      SizedBox(height: 4.h),
                      Text(
                        order.phone ?? "",
                        style: TextStyle(
                          fontSize: 12.sp,
                          color: AppColor.color666666,
                        ),
                      ),
                    ],
                  ),
                ),
                // 订单状态
                // Container(
                //   padding: EdgeInsets.symmetric(horizontal: 8.w, vertical: 4.h),
                //   decoration: BoxDecoration(
                //     color: order.status == "1" ? AppColor.colorE1F4E7 : AppColor.colorFFEAEA,
                //     borderRadius: BorderRadius.circular(4.w),
                //   ),
                //   child: Text(
                //     order.status == "1" ? "已完成" : "待处理",
                //     style: TextStyle(
                //       fontSize: 12.sp,
                //       color: order.status == "1" ? AppColor.color21A95E : AppColor.primary,
                //     ),
                //   ),
                // ),
              ],
            ),
          ),
          
        const  WidgetLine(),
          
          // 商品信息部分
          Padding(
            padding: EdgeInsets.all(12.w),
            child: Row(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: [
                // 商品图片
                ClipRRect(
                  borderRadius: BorderRadius.circular(6.w),
                  child: ImageView(
                    imageUrl: order.image,
                    width: 80.w,
                    height: 80.w,
                    fit: BoxFit.cover,
                  ),
                ),
                SizedBox(width: 10.w),
                // 商品信息
                Expanded(
                  child: Column(
                    crossAxisAlignment: CrossAxisAlignment.start,
                    children: [
                      Text(
                        order.storeName ?? "",
                        maxLines: 2,
                        overflow: TextOverflow.ellipsis,
                        style: TextStyle(
                          fontSize: 13.sp,
                          color: AppColor.color202020,
                        ),
                      ),
                      SizedBox(height: 8.h),
                      Row(
                        mainAxisAlignment: MainAxisAlignment.spaceBetween,
                        children: [
                          Text(
    // ¥
                            UtilsOther.getGoodsPrice(order.price),
                            // "¥${(order.price ??'')}",
                            style: TextStyle(
                              fontSize: 15.sp,
                              fontWeight: FontWeight.bold,
                              color: AppColor.primary,
                            ),
                          ),

                        ],
                      ),
                    ],
                  ),
                ),
              ],
            ),
          ),
          

        ],
      ),
    );
  }
}
